package com.ruoyi.huanghefd.controller;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.huanghefd.domain.Worksheet;
import com.ruoyi.huanghefd.domain.WorksheetTemplate;
import com.ruoyi.huanghefd.service.WorksheetTemplateService;
import com.ruoyi.huanghefd.utils.PageBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author gnplum
 * @Date 2024/1/23 16:33
 * @PackageName:com.ruoyi.huanghefd.controller
 * @ClassName: WorksheetTemplateController
 * @Description: TODO
 * @Version 1.0
 */
@RestController
@RequestMapping("/huanghefd")
public class WorksheetTemplateController {
    private static final Logger log = LoggerFactory.getLogger(WorksheetTemplateController.class);

    @Resource
    WorksheetTemplateService worksheetTemplateService;

    /**
     * @Author gnplum
     * @Description //工作票模板  新增
     * @Date 16:36 2024/1/23
     * @param worksheetTemplate
    * @return com.ruoyi.common.core.domain.AjaxResult
    **/
    @PostMapping("/addWorksheetTemplate")
    public AjaxResult addWorksheetTemplate(@RequestBody WorksheetTemplate worksheetTemplate){
        log.info(">> 新增工作票模板-入参==" + JSON.toJSONString(worksheetTemplate));
        AjaxResult ajax = worksheetTemplateService.addWorksheetTemplate(worksheetTemplate);
        log.info("<< 新增工作票模板-返回==" + ajax.toString());
        return ajax;
    }

    /**
     * @Author gnplum
     * @Description //工作票模板  删除
     * @Date 16:38 2024/1/23
     * @param id
    * @return com.ruoyi.common.core.domain.AjaxResult
    **/
    @PostMapping(value = "/delWorksheetTemplate")
    public AjaxResult delWorksheetTemplate(@RequestParam(required = false,value = "id") String id){
        log.info(">> 删除工作票模板-入参 id==" + id);
        if(id.isEmpty()){
            return AjaxResult.success("请点选要删除的工作票模板");
        }
        AjaxResult ajax = worksheetTemplateService.delWorksheetTemplate(id);
        log.info(">> 删除工作票模板-返回==" + ajax);
        return ajax;
    }
    /**
     * @Author gnplum
     * @Description //工作票模板 修改
     * @Date 16:40 2024/1/23
     * @param worksheetTemplate
    * @return com.ruoyi.common.core.domain.AjaxResult
    **/
    @PostMapping("/uptWorksheetTemplate")
    public AjaxResult uptWorksheetTemplate(@RequestBody WorksheetTemplate worksheetTemplate){
        log.info(">> 修改工作票模板-入参==" + JSON.toJSONString(worksheetTemplate));
        AjaxResult ajax = worksheetTemplateService.uptWorksheetTemplate(worksheetTemplate);
        log.info("<< 修改工作票模板-返回==" + ajax.toString());
        return ajax;
    }

    @PostMapping(value = "/queryWorksheetTemplate")
    public PageBean queryWorksheetTemplateList(@RequestParam(required = false, value = "wsType") String wsType,
                                               @RequestParam(required = false, value = "deviceCode") String deviceCode,
                                               @RequestParam(required = false, value = "deviceName") String deviceName,
                                               @RequestParam(required = false, value = "id") String id,
                                               @RequestParam(required = false, value = "sponsor") String sponsor,
                                               @RequestParam(required = false, value = "receiver") String receiver,
                                               @RequestParam(required = false, value = "approver1") String approver1,
                                               @RequestParam(required = false, value = "state") String state,
                                               @RequestParam(required = false, value = "userId") String userId,
                                               @RequestParam(value = "pageNum") int pageNum,
                                               @RequestParam(value = "pageSize") int pageSize) {
        log.info(">> 查询工作票模板-入参==" + wsType + "," + deviceCode + "," + deviceName);
        PageBean ajax = worksheetTemplateService.queryWorksheetTemplateByPage(wsType, deviceCode, deviceName, id, sponsor, receiver, approver1, state, userId, pageNum, pageSize);
        log.info(">> 查询工作票模板-返回==" + ajax);
        return ajax;
    }

}
